package com.tedu.oop.day1;

public class Test2_Constructor {
    public static void main(String[] args) {
        //new---实例化对象
        Person p=new Person();
        p.setName("唐僧");p.setAge(30);p.setAddress("东土大唐");
        System.out.println(p.getName()+p.getAge()+p.getAddress());
        System.out.println("=================================");
        Person p1=new Person("孙悟空",500,"花果山");
        System.out.println(p1.getName()+p1.getAge()+p1.getAddress());

    }
}
class Person{
    private String name;//姓名
    private int age;//年龄
    private String address;//住址

    public Person() {
        System.out.println("我是无参构造函数");
    }

    public Person(String name, int age) {
        System.out.println("我是两个参数构造函数");
        this.name = name;
        this.age = age;
    }

    public Person(String name, int age, String address) {
        System.out.println("我是全参构造函数");
        this.name = name;
        this.age = age;
        this.address = address;
    }

    {
        System.out.println("我是构造代码块");
    }

    static{
        System.out.println("我是静态代码块");
    }


    //私有方法-通过公共方法调用
    private void study(){
        System.out.println("学习爪哇");
    }
    //私有方法
    private void eat(){
        System.out.println("吃饭吃饭");
    }

    public void method(){
        System.out.println("公共方法调用: ");
        study();
        eat();
    }


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }
}
